<?php
class UserApp extends CommonApp {
   
   	//用户栏目界面
    public function indexAct(){
    	$this->checkLogin();
    	$userid = My::arr2var($_SESSION,'member.memberid');
    	$result = DB('homeuser')->clear()->where("id={$userid}")->find();
    	$this->assign('result',$result);
		$this->display();
    }

    //用户修改界面
    public function infoAct(){
    	if(!My::is_string($_POST['username'],array('c')))
    		$this->ajaxReturn(300,'姓名填写有误！');
    	if(!My::is_email($_POST['email']))
    		$this->ajaxReturn(300,'邮箱填写有误！');
    	$userid = My::arr2var($_SESSION,'member.memberid');
    	$result = DB('homeuser')->clear()->where("id={$userid}")->find();
    	if(md5(md5($_POST['old_password'])) != $result['password'])
    		$this->ajaxReturn(300,'初始密码填写有误！');
    	if(!My::is_string($_POST['new_password']))
    		$this->ajaxReturn(300,'新密码填写有误！');
		if($_POST['new_password'] !== $_POST['confirm_password'])
    		$this->ajaxReturn(300,'两次密码输入不一致！');
    	$_POST['password'] = md5(md5($_POST['new_password']));
        $_POST['editdate'] = date("Y-m-d H:i:s");
    	$ok = DB('homeuser')->clear()->where("id={$userid}")->save($_POST);
    	if($ok>=0){
            unset($_SESSION['member']['memberid']);
            $this->ajaxReturn(200,"密码修改成功,请重新登录！");
        }else		$this->ajaxReturn(300,"密码修改失败！");
    }
   
}